#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    resize(800, 600);

    QPushButton* btn = new QPushButton("消息对话框", this);
    QMessageBox* msg = new QMessageBox(this);

    msg->setWindowTitle("Warning Message");//设置消息对话框的框体
    msg->setText("Error Message!");//设置消息对话框的内容
    msg->setIcon(QMessageBox::Question); //设置消息对话框类型
    // msg->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); //在消息对话框上设置按钮
    msg->setStandardButtons(QMessageBox::Open | QMessageBox::Close ); //在消息对话框上设置按钮

    connect(btn, &QPushButton::clicked, [=](){
        msg->show();
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}
